/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.StyleConstants;
import project.jpdfexport.constants.JPDFConst.ALIGNMENT;
import project.jpdftools.ui.logic.JPDFText;
import project.jpdftools.managers.LoggerManager;

/**
 *
 * @author Mido
 */
public class AlignLeftAction implements ActionListener {

    private Object component;

    public AlignLeftAction(Object component) {
        super();
        this.component = component;
    }

    public void actionPerformed(ActionEvent evt) {
        if (component instanceof JPDFText) {
            JPDFText text = (JPDFText) component;
            // apply the alignment in the UI
            MutableAttributeSet attrs = text.getTextPane().getInputAttributes();
            StyleConstants.setAlignment(attrs, StyleConstants.ALIGN_LEFT);
            text.getTextPane().setParagraphAttributes(attrs, false);

            // set the left option to be selected
            text.getMiAlignLeft().setSelected(true);
            // de-select the two other options
            text.getMiAlignCenter().setSelected(false);
            text.getMiAlignRight().setSelected(false);

            // apply alignment in the component attributes
            text.setTextAlignment(ALIGNMENT.left);
            LoggerManager.getLogger().log(Level.INFO, "Component aligned to left. Component ID = {0}", text.getId());
        }
    }
}
